//
//  WWTextTableCell.m
//  YiQiTingShu
//
//  Created by WeiWei on 15/11/10.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//

#import "WWTextTableCell.h"
#import "PublicHeader.h"

@interface WWTextTableCell ()

@property (nonatomic, strong) UILabel *userLabel;
@property (nonatomic, strong) UIImageView *userImageView;
@property (nonatomic, strong) UILabel *contentText;
@property (nonatomic, assign) CGRect height;

@end

@implementation WWTextTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _userImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_userImageView];
        _userLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_userLabel];
        _contentText = [[UILabel alloc] init];
        [self.contentView addSubview:_contentText];
        [self.userLabel NightWithType:UIViewColorTypeNormal];
        [self.contentText NightWithType:UIViewColorTypeNormal];
        [self.contentView NightWithType:UIViewColorTypeNormal];
    }
    return self;
}

- (void)setWModel:(WWTextModel *)wModel {
    if (_wModel != wModel) {
        _wModel = wModel;
    }
    if ([wModel.user objectForKey:@"login"]) {
        self.userLabel.text = [wModel.user objectForKey:@"login"];

    } else {
        self.userLabel.text = @"匿名用户";
    }
    self.userLabel.textColor = [UIColor orangeColor];
    self.userImageView.image = [UIImage imageNamed:@"sanjiao.png"];
    self.userImageView.layer.cornerRadius = 10;
    self.userImageView.layer.masksToBounds = YES;
    self.contentText.text = wModel.content;
    self.contentText.numberOfLines = 0;
    _height = [wModel.content boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:17]} context:nil];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.userImageView.frame = CGRectMake(FitConstant_XorWidth(5), FitConstant_YorHeight(3), FitConstant_XorWidth(20), FitConstant_YorHeight(20));
    self.userLabel.frame = CGRectMake(FitConstant_XorWidth(28), FitConstant_YorHeight(3), FitConstant_YorHeight(150), FitConstant_YorHeight(20));
    self.contentText.frame = CGRectMake(FitConstant_XorWidth(5), FitConstant_YorHeight(30), FitConstant_XorWidth(365), FitConstant_YorHeight(_height.size.height));
}

@end
